package com.purong.purong.activity;

import android.content.Intent;
import android.os.Handler;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.purong.purong.Contant;
import com.purong.purong.R;
import com.purong.purong.adapter.CreditSearchListAdapter;
import com.purong.purong.bean.BankBean;
import com.purong.purong.bean.CreditBankListBean;
import com.purong.purong.bean.CreditCardBean;
import com.purong.purong.bean.CreditSearchBean;
import com.purong.purong.bean.CreditSearchBean.SearchType;
import com.purong.purong.bean.CreditSearchBean.SearchType.SearchItem;
import com.purong.purong.bean.CreditSearchListBean;
import com.purong.purong.bean.SearchValueBean;
import com.purong.purong.util.CommonUtil;
import com.purong.purong.util.SharePreUtil;
import com.purong.purong.widget.RadiusImageView;
import com.purong.purong.widget.SearchBankDialog;
import com.purong.purong.widget.SearchNormalDialog;
import com.purong.purong.widget.SearchMoreDialog;
import com.purong.purong.widget.LoadingView;
import com.yao.sdk.glide.GlideUtil;
import com.yao.sdk.net.ResponseInfo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import in.srain.cube.views.ptr.PtrCustomHandler;
import in.srain.cube.views.ptr.PtrDefaultCustomHandler;
import in.srain.cube.views.ptr.PtrFrameLayout;
import in.srain.cube.views.ptr.PtrPuRongLayout;

/**
 * Created by wenjiezeng on 2017/9/25.
 */
public class CreditSearchActivity extends BaseActivity {
    private LinearLayout titleBar;
    private ArrayList<BankBean> mBankList ;
    private SearchBankDialog dialog;
    private SearchNormalDialog useSearchDialog,levelSearchDialog;
    private SearchMoreDialog moreSearchDialog;
    private TextView titleTv,bankName,bankOutLine,throughRate,ratifyVel,
            useTv,levelTv,moreTv;
    private ImageView titleImg,useImg,levelImg,moreImg;
    private RadiusImageView bankImg;
    private BankBean choseBank;
    private SearchValueBean choseUse, choseLevel;
    private List<SearchValueBean> choseMoreList=new ArrayList<>();
    private ArrayList<SearchValueBean> mUseList;
    private ArrayList<SearchValueBean> mLevelList;
    private ArrayList<SearchItem> mMoreList;
    private RecyclerView mRecyclerView;
    private CreditSearchListAdapter mAdapter;
    private List<CreditCardBean> creditList=new ArrayList<>();
    private View headView;
     private PtrPuRongLayout mPtrFrame;
    private LoadingView loadView;
    private CreditSearchBean searchBean;
    private int page=1;

//    private SearchValueBean choseUse,choseLevel;
    private Map<String,String> itemMap=new HashMap<>();

    @Override
    public int getRootViewId() {
        return R.layout.activity_credit_search;
    }

    public void initView(){
        loadView=(LoadingView)findViewById(R.id.loading_view);
        loadView.setNoResultToast("未找到符合条件的信用卡","清空筛选");
        loadView.setLoadListener(new LoadingView.OnLoadListener() {
            @Override
            public void onReload() {
                getCredit(true);
            }

            @Override
            public void onRefresh() {
                if (mBankList!=null){
                    for (int i = 0; i <mBankList.size() ; i++) {
                        if (mBankList.get(i).getBank_id().equals("-1")){
                            mBankList.get(i).setCheck(true);
                            choseBank=mBankList.get(i);
                        }else {
                            mBankList.get(i).setCheck(false);
                        }
                    }
                }
                if (mUseList!=null){
                    for (int i = 0; i <mUseList.size() ; i++) {
                        if (mUseList.get(i).getItem().equals("-1")){
                            mUseList.get(i).setCheck(true);
                            choseUse =mUseList.get(i);

                        }else {
                            mUseList.get(i).setCheck(false);
                        }
                    }
                }
                if (mLevelList!=null){
                    for (int i = 0; i <mLevelList.size() ; i++) {
                        if (mLevelList.get(i).getItem().equals("-1")){
                            mLevelList.get(i).setCheck(true);
                            choseLevel =mLevelList.get(i);
                        }else {
                            mLevelList.get(i).setCheck(false);
                        }
                    }
                }
                if (mMoreList!=null){
                    for (int i = 0; i <mMoreList.size() ; i++) {
                        for (int j = 0; j <mMoreList.get(i).getValue().size() ; j++) {
                            mMoreList.get(i).getValue().get(j).setCheck(false);
                        }
                    }
                }

                titleTv.setText("全部银行");
                setStatus(titleTv,titleImg,1);
                useTv.setText("全部用途");
                setStatus(useTv,useImg,1);
                levelTv.setText("全部等级");
                setStatus(levelTv,levelImg,1);
                setStatus(moreTv,moreImg,1);
                getCredit(true);
            }
        });
        headView = getLayoutInflater().inflate(R.layout.credit_search_head,null);
        headView.findViewById(R.id.bank_info_lay).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (choseBank!=null){
                    Intent intent=new Intent(CreditSearchActivity.this,BankDetialActivity.class);
                    intent.putExtra("BANK",choseBank);
                    startActivity(intent);
                }

            }
        });
        bankName=(TextView)headView.findViewById(R.id.bank_name);
        bankOutLine=(TextView)headView.findViewById(R.id.bank_outline);
        throughRate=(TextView)headView.findViewById(R.id.through_rate);
        ratifyVel=(TextView)headView.findViewById(R.id.ratify_velocity);
        bankImg=(RadiusImageView) headView.findViewById(R.id.bank_img);
        mRecyclerView=(RecyclerView)findViewById(R.id.recycler_view);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mAdapter=new CreditSearchListAdapter(this);
        mAdapter.setData(creditList);
        mAdapter.addHeaderView(headView);
        mAdapter.setOnCreditClickListener(new CreditSearchListAdapter.OnCreditClickListener() {
            @Override
            public void onCreditClick(CreditCardBean card) {
                Intent intent=new Intent(CreditSearchActivity.this, CreditDetialActivity.class);
                intent.putExtra("CREDIT",card);
                startActivity(intent);
            }
        });
        mRecyclerView.setAdapter(mAdapter);
        mPtrFrame = (PtrPuRongLayout) findViewById(R.id.rotate_header_list_view_frame);
        mPtrFrame.setPtrHandler(new PtrCustomHandler() {
            @Override
            public boolean checkCanDoLoadMore(PtrFrameLayout frame, View content, View footer) {
                if (creditList.size()==0){
                    return false;
                }else {
                    return PtrDefaultCustomHandler.checkContentCanBePulledUp(frame, content, footer);
                }

            }

            @Override
            public void onLoadMoreBegin(PtrFrameLayout frame) {
                getCredit(false);

            }

            @Override
            public void onRefreshBegin(PtrFrameLayout frame) {
                getCredit(true);
            }

            @Override
            public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
                return false;
            }
        });
        useTv=(TextView)findViewById(R.id.use_tv);
        levelTv=(TextView)findViewById(R.id.level_tv);
        moreTv=(TextView)findViewById(R.id.more_tv);
        int maxWidth= CommonUtil.getScreenWidth(this)/3-CommonUtil.dip2px(this,20);
        useTv.setMaxWidth(maxWidth);
        moreTv.setMaxWidth(maxWidth);
        useTv.setMaxWidth(maxWidth);
        useImg=(ImageView)findViewById(R.id.use_img);
        levelImg=(ImageView)findViewById(R.id.level_img);
        moreImg=(ImageView)findViewById(R.id.more_img);
        titleBar=(LinearLayout)findViewById(R.id.title_bar);
        titleTv=(TextView)findViewById(R.id.title_tv);
        titleImg=(ImageView)findViewById(R.id.title_img);

        if (choseBank!=null){
            titleTv.setText(choseBank.getBank_name());
            setStatus(titleTv,titleImg,2);

        }else {
            titleTv.setText("全部银行");
            setStatus(titleTv,titleImg,1);
        }

    }

    @Override
    public void initBundle() {
        mBankList=(ArrayList)getIntent().getSerializableExtra("BANK_LIST");
        choseBank=(BankBean)getIntent().getSerializableExtra("CHOSE_BANK");
        choseUse=(SearchValueBean)getIntent().getSerializableExtra("CHOSE_USE");
        choseLevel=(SearchValueBean)getIntent().getSerializableExtra("CHOSE_LEVEL");
        choseMoreList=(List<SearchValueBean>)getIntent().getSerializableExtra("CHOSE_MORE");
    }

    @Override
    public void initData() {

        if (mBankList!=null){
            BankBean defBean=new BankBean();
            defBean.setBank_name("全部银行");
            defBean.setBank_id("-1");
            mBankList.add(0,defBean);
            if (choseBank!=null){
                for (int i = 0; i <mBankList.size() ; i++) {
                    if (mBankList.get(i).getBank_id().equals(choseBank.getBank_id())){
                        mBankList.get(i).setCheck(true);
                        titleTv.setText(choseBank.getBank_name());
                        setStatus(titleTv,titleImg,2);
                        break;
                    }
                }
            }else {
                defBean.setCheck(true);
                setStatus(titleTv,titleImg,1);
            }

        }else {
            getBankList("1");
        }

        getSearch("2","1","1");

    }

    private void setBankInfo(){
        if (choseBank==null||choseBank.getBank_id().equals("-1")){
            headView.findViewById(R.id.bank_info_lay).setVisibility(View.GONE);
        }else {
            GlideUtil.getInstance().load(this,choseBank.getBank_url(),bankImg,true);
            bankName.setText(choseBank.getBank_name());
            bankOutLine.setText(choseBank.getBank_outline());
            throughRate.setText("通过率"+choseBank.getThrough_rate());
            ratifyVel.setText(choseBank.getRatify_velocity());
            headView.findViewById(R.id.bank_info_lay).setVisibility(View.VISIBLE);
            switch (Integer.valueOf(choseBank.getBank_id())%4){
                case 0:
                    headView.findViewById(R.id.bank_info_lay).setBackgroundResource(R.drawable.gradient_blue);
                    break;
                case 1:
                    headView.findViewById(R.id.bank_info_lay).setBackgroundResource(R.drawable.gradient_purple);
                    break;
                case 2:
                    headView.findViewById(R.id.bank_info_lay).setBackgroundResource(R.drawable.gradient_green);
                    break;
                case 3:
                    headView.findViewById(R.id.bank_info_lay).setBackgroundResource(R.drawable.gradient_red);
                    break;
            }
        }
    }

    private void setStatus(TextView tv,ImageView iv,int status){
        //status 1:下黑，2：下蓝，3：上黑，4：上篮
        switch (status){
            case 1:
                tv.setTextColor(getResources().getColor(R.color.text_dark_gray));
                iv.setImageResource(R.drawable.cart_black_down);
                break;
            case 2:
                tv.setTextColor(getResources().getColor(R.color.blue));
                iv.setImageResource(R.drawable.cart_blue_down);
                break;
            case 3:
                tv.setTextColor(getResources().getColor(R.color.text_dark_gray));
                iv.setImageResource(R.drawable.cart_black_up);
                break;
            case 4:
                tv.setTextColor(getResources().getColor(R.color.blue));
                iv.setImageResource(R.drawable.cart_blue_top);
                break;
        }
    }
    private void initSearchData(){
        if (searchBean==null)
            return;
        List<SearchType> typeList=searchBean.getCredit_credit_item_list();
        for (int i = 0; i <typeList.size() ; i++) {
            for (int j = 0; j <typeList.get(i).getSearch_item().size() ; j++) {
                for (int k = 0; k <typeList.get(i).getSearch_item().get(j).getValue().size() ; k++) {
                    if (choseUse!=null&&typeList.get(i).getSearch_item().get(j).getFiled().equals(choseUse.getParentFiled())
                            &&typeList.get(i).getSearch_item().get(j).getValue().get(k).getItem().equals(choseUse.getItem())){
                        typeList.get(i).getSearch_item().get(j).getValue().get(k).setCheck(true);
                        choseUse.setTitle(typeList.get(i).getSearch_item().get(j).getValue().get(k).getTitle());
                        useTv.setText(typeList.get(i).getSearch_item().get(j).getValue().get(k).getTitle());
                        setStatus(useTv,useImg,2);
                        continue;
                    }
                    if (choseLevel!=null&&typeList.get(i).getSearch_item().get(j).getFiled().equals(choseLevel.getParentFiled())
                            &&typeList.get(i).getSearch_item().get(j).getValue().get(k).getItem().equals(choseLevel.getItem())){
                        typeList.get(i).getSearch_item().get(j).getValue().get(k).setCheck(true);
                        choseLevel.setTitle(typeList.get(i).getSearch_item().get(j).getValue().get(k).getTitle());
                        levelTv.setText(typeList.get(i).getSearch_item().get(j).getValue().get(k).getTitle());
                        setStatus(levelTv,levelImg,2);
                        continue;
                    }
                    if (choseMoreList!=null){
                        boolean hasMore=false;
                        for (int n = 0; n <choseMoreList.size() ; n++) {
                            if (typeList.get(i).getSearch_item().get(j).getFiled().equals(choseMoreList.get(n).getParentFiled())
                                    &&typeList.get(i).getSearch_item().get(j).getValue().get(k).getItem().equals(choseMoreList.get(n).getItem())){
                                typeList.get(i).getSearch_item().get(j).getValue().get(k).setCheck(true);
                                hasMore=true;
                                break;
                            }
                        }
                        if (hasMore){
                            setStatus(moreTv,moreImg,2);
                        }
                    }

                }

            }
        }

    }
    private void getCredit(boolean clear){
        Map<String, String> params = new LinkedHashMap<String, String>();
        params.put("province_id",SharePreUtil.getInstance(this).getLoactionParentId());
        params.put("city_id",SharePreUtil.getInstance(this).getLoactionAreaId());

        if (choseBank!=null&&choseBank.getBank_id()!="-1"){
            params.put("bank_id",choseBank.getBank_id());
            Log.e("zwj",".....bank_id="+choseBank.getBank_id());
        }
        if (searchBean!=null&&searchBean.getCredit_credit_item_list()!=null){
            itemMap.clear();
            List<SearchType> typeList=searchBean.getCredit_credit_item_list();
            for (int i = 0; i <typeList.size() ; i++) {
                for (int j = 0; j <typeList.get(i).getSearch_item().size() ; j++) {
                    for (int k = 0; k <typeList.get(i).getSearch_item().get(j).getValue().size() ; k++) {
                        if (typeList.get(i).getSearch_item().get(j).getValue().get(k).isCheck()){
                            itemMap.put(typeList.get(i).getSearch_item().get(j).getFiled(),typeList.get(i).getSearch_item().get(j).getValue().get(k).getItem());
                        }
                    }
                }
            }
            for (Map.Entry<String, String> entry : itemMap.entrySet()) {
                params.put(entry.getKey(),entry.getValue());
            }
        }

        if (clear){
            page=1;
            creditList.clear();
            mAdapter.notifyDataSetChanged();
            loadView.loading();

        }
        params.put("page",page+"");
        Log.e("zwj",".....page="+page);

        if (!request(Contant.CREDIT_SEARCH_LIST, params, true)) {
            if (clear)
            loadView.fail();
            if (!hasDestroy())
                new Handler().postDelayed(new Runnable() {
                    public void run() {
                        if (mPtrFrame.isRefreshing()) {
                            mPtrFrame.refreshComplete();
                        }
                    }
                }, 100);
        }
    }
    private void getSearch(String firstLoad,String needShow,String type){
        cancelRequest();
        Map<String, String> params = new LinkedHashMap<String, String>();
        params.put("first_load",firstLoad);
        params.put("need_show",needShow);
        params.put("type",type);
        if (needShow.equals("1")){
            request(Contant.CREDIT_SEARCH, params, true, false);
        }else {
            request(Contant.CREDIT_SEARCH, params, true, true);
        }

    }
    private void getBankList(String needShow){
        Map<String, String> params = new LinkedHashMap<String, String>();
        params.put("city_id", SharePreUtil.getInstance(this).getLoactionAreaId());
        params.put("need_show",needShow);
        if (needShow.equals("1")){
            request(Contant.BANK, params, true, false);
        }else {
            request(Contant.BANK, params, true, true);
        }
    }
    private void initBankDialog(){
        dialog=new SearchBankDialog(this, titleBar, mBankList, new SearchBankDialog.OnBankChoseListener() {
            @Override
            public void onChose(int position) {
                choseBank=mBankList.get(position);
                getCredit(true);
            }

            @Override
            public void onShow() {
                setStatus(titleTv,titleImg,4);
            }

            @Override
            public void onDismiss() {
                if (choseBank!=null){
                    if (choseBank.getBank_id().equals("-1")){
                        titleTv.setText("全部银行");
                        setStatus(titleTv,titleImg,1);
                    }else {
                        titleTv.setText(choseBank.getBank_name());
                        setStatus(titleTv,titleImg,2);
                    }

                }else {
                    setStatus(titleTv,titleImg,1);
                }

            }
        });
        dialog.show();
    }
    private void initUseDialog(){
        useSearchDialog=new SearchNormalDialog(this, mUseList,true, false,new SearchNormalDialog.OnSearchChoseListener() {
            @Override
            public void onChose(int position) {
                choseUse =mUseList.get(position);
                getCredit(true);
            }

            @Override
            public void onShow() {
                setStatus(useTv,useImg,4);
            }

            @Override
            public void onDismiss() {
                if (choseUse != null) {
                    useTv.setText(choseUse.getTitle());
                    if (choseUse.getItem().equals("-1")) {
                        setStatus(useTv,useImg,1);
                    } else {
                        setStatus(useTv,useImg,2);
                    }

                } else {
                    setStatus(useTv,useImg,1);
                }


            }
        });
    }
    private void initLevelDialog(){
        levelSearchDialog=new SearchNormalDialog(this, mLevelList,false, false,new SearchNormalDialog.OnSearchChoseListener() {
            @Override
            public void onChose(int position) {
                choseLevel =mLevelList.get(position);
                getCredit(true);
            }

            @Override
            public void onShow() {
                setStatus(levelTv,levelImg,4);
            }

            @Override
            public void onDismiss() {
                if (choseLevel != null) {
                    levelTv.setText(choseLevel.getTitle());
                    if (choseLevel.getItem().equals("-1")) {
                        setStatus(levelTv,levelImg,1);
                    } else {
                        setStatus(levelTv,levelImg,2);
                    }

                } else {
                    setStatus(levelTv,levelImg,1);
                }

            }
        });
        levelSearchDialog.show();
    }
    private void initMoreDialog(){
        moreSearchDialog=new SearchMoreDialog(this, mMoreList,false, new SearchMoreDialog.OnSearchChoseListener() {
            @Override
            public void onConfirm() {
                getCredit(true);
            }

            @Override
            public void onShow() {
                setStatus(moreTv,moreImg,4);
            }

            @Override
            public void onDismiss() {
                boolean hasCheck=false;
                for (int i = 0; i <mMoreList.size() ; i++) {
                    for (int j = 0; j <mMoreList.get(i).getValue().size() ; j++){
                        if (mMoreList.get(i).getValue().get(j).isCheck()){
                            hasCheck=true;
                            break;
                        }
                    }
                }
                if (hasCheck){
                    setStatus(moreTv,moreImg,2);
                }else {
                    setStatus(moreTv,moreImg,1);
                }
            }
        });
        moreSearchDialog.show();
    }

    public void onClick(View v){
        switch (v.getId()){

            case R.id.use_lay:
                if (useSearchDialog==null){
                    if (mUseList==null){
                        getSearch("1","2","1");
                    }else {
                        initUseDialog();
                        useSearchDialog.show();
                    }
                }else {
                    useSearchDialog.show();
                }
                break;
            case R.id.level_lay:
                if (levelSearchDialog==null){
                    if (mLevelList==null){
                        getSearch("1","2","2");
                    }else {
                        initLevelDialog();
                    }
                }else {
                    levelSearchDialog.show();
                }
                break;
            case R.id.more_lay:
                if (moreSearchDialog==null){
                    if (mMoreList==null){
                        getSearch("1","2","3");
                    }else {
                        initMoreDialog();
                    }
                }else {
                    moreSearchDialog.show();
                }
                break;
            case R.id.title_bar:
                if (findViewById(R.id.search_lay).getVisibility()==View.GONE)
                    return;
                if (dialog==null){
                    if (mBankList==null){
                        getBankList("2");
                    }else {
                        initBankDialog();
                    }
                }else {
                    dialog.show();
                }
                break;
            case R.id.left_back:
                this.finish();
                break;
        }
    }
    @Override
    public void onResponse(ResponseInfo responseInfo) {
        if (hasDestroy())
            return;
        super.onResponse(responseInfo);
        if (responseInfo.url.equals(Contant.BANK)){
            if (responseInfo.isRequestOk){
                try{
                    CreditBankListBean bankListBean= JSON.parseObject(responseInfo.content,CreditBankListBean.class);
                    if (bankListBean!=null&&bankListBean.getBank_list()!=null){
                        mBankList=new ArrayList<>();
                        mBankList.addAll(bankListBean.getBank_list());
                        BankBean defBean=new BankBean();
                        defBean.setBank_name("全部银行");
                        defBean.setBank_id("-1");
                        mBankList.add(0,defBean);
                        if (choseBank!=null){
                            for (int i = 0; i <mBankList.size() ; i++) {
                                if (mBankList.get(i).getBank_id().equals(choseBank.getBank_id())){
                                    mBankList.get(i).setCheck(true);
                                    titleTv.setText(choseBank.getBank_name());
                                    setStatus(titleTv,titleImg,2);
                                    break;
                                }
                            }
                        }else {
                            defBean.setCheck(true);
                            setStatus(titleTv,titleImg,1);
                        }
                        if (responseInfo.params.get("need_show").equals("2")){
                            initBankDialog();
                            dialog.show();
                        }

                    }
                }catch (Exception e){
                    Log.e("zwj",e.toString());
                    showToast(e.toString());
                }
            }
        }else if (responseInfo.url.equals(Contant.CREDIT_SEARCH)){
            findViewById(R.id.search_lay).setVisibility(View.VISIBLE);
            if (responseInfo.isRequestOk){
                try{
                     searchBean=JSON.parseObject(responseInfo.content,CreditSearchBean.class);
                    if (searchBean!=null&&searchBean.getCredit_credit_item_list()!=null){
                        for (int i = 0; i <searchBean.getCredit_credit_item_list().size() ; i++) {
                            if (searchBean.getCredit_credit_item_list().get(i).getSearch_type().equals("1")){
                                mUseList=new ArrayList<>();
                                if (searchBean.getCredit_credit_item_list().get(i).getSearch_item()!=null&&
                                        searchBean.getCredit_credit_item_list().get(i).getSearch_item().size()>0)
                                mUseList.addAll(searchBean.getCredit_credit_item_list().get(i).getSearch_item().get(0).getValue());
                                SearchValueBean value=new SearchValueBean();
                                if (choseUse==null)
                                value.setCheck(true);
                                value.setTitle("全部用途");
                                value.setItem("-1");
                                mUseList.add(0,value);

                            }else if (searchBean.getCredit_credit_item_list().get(i).getSearch_type().equals("2")){
                                mLevelList=new ArrayList<>();
                                if (searchBean.getCredit_credit_item_list().get(i).getSearch_item()!=null&&
                                        searchBean.getCredit_credit_item_list().get(i).getSearch_item().size()>0)
                                    mLevelList.addAll(searchBean.getCredit_credit_item_list().get(i).getSearch_item().get(0).getValue());
                                SearchValueBean value=new SearchValueBean();
                                if (choseLevel==null)
                                value.setCheck(true);
                                value.setTitle("全部等级");
                                value.setItem("-1");
                                mLevelList.add(0,value);
                            }else if (searchBean.getCredit_credit_item_list().get(i).getSearch_type().equals("3")){
                                mMoreList=new ArrayList<>();
                                if (searchBean.getCredit_credit_item_list().get(i).getSearch_item()!=null&&
                                        searchBean.getCredit_credit_item_list().get(i).getSearch_item().size()>0)
                                    mMoreList.addAll(searchBean.getCredit_credit_item_list().get(i).getSearch_item());
                            }
                        }
                        if (responseInfo.params.get("first_load").equals("2")){
                            initSearchData();
                            getCredit(true);
                        }
                        if (responseInfo.params.get("need_show").equals("2")){
                            if (responseInfo.params.get("type").equals("1")){
                                initUseDialog();
                                useSearchDialog.show();
                            }else if (responseInfo.params.get("type").equals("2")){
                                initLevelDialog();
                                levelSearchDialog.show();
                            }else if (responseInfo.params.get("type").equals("3")){
                                initMoreDialog();
                                moreSearchDialog.show();
                            }

                        }
                    }
                }catch (Exception e){

                }

            }
        }else if (responseInfo.url.equals(Contant.CREDIT_SEARCH_LIST)){
            if (mPtrFrame.isRefreshing()) {
                mPtrFrame.refreshComplete();
            }

            if (responseInfo.isRequestOk){
                try{
                    CreditSearchListBean bean=JSON.parseObject(responseInfo.content,CreditSearchListBean.class);
                    if (bean!=null&&bean.getCredit_search_list()!=null){
                        if (bean.getCredit_search_list().size()>0)
                        page++;
                        creditList.addAll(bean.getCredit_search_list());
                        mAdapter.notifyDataSetChanged();

                    }
                    if (creditList.size()==0){
                        headView.findViewById(R.id.bank_info_lay).setVisibility(View.GONE);

                        if (itemMap.size()==0&&(choseBank==null||choseBank.getBank_id().equals("-1"))){
                            loadView.noResult();
                        }else {
                            loadView.noResultWithRefresh();
                        }

                    }else {
                        setBankInfo();
                        loadView.finish();
                    }

                }catch (Exception e){
                    if (page == 1){
                        loadView.fail();
                    }
                }
            }else {
                if (page == 1){
                    loadView.fail();
                }
            }
        }
    }
}
